Me Keyword
Me refers to the control that fired the current event. Outside an event handler, it simply refers to the current object ( Self).
Notes
When called within an event handler or method of a control on a form, Me will always be a reference to the control that owns the event handler or method where Me was called. Me is only different from Self inside an event handler for a control on a window.
This means that in PushButton1's Action event handler:
and
mean the same thing. When Me is called within the method of a class, Me will be a reference to the instance of the class in use. The Me keyword is different from the Self keyword in that Self always refers to the object's parent and not the object itself.
For code for a control in a window, Self refers to the window, and Me refers to the control.
One big advantage of using the Me keyword when referring to a control in one of its event handlers is that if you change the name of the control, the code in its own event handlers will not need to be updated. Also, you can copy the code to another control of the same type and it will work without modification.
Examples
Me can be use in place of a control's name inside any of its event handlers. For example, this example in the Open event of a ListBox sets the column widths and populates the header row:
Me.columnwidths="0,25%,25%,25%,25%"
Me.heading(0)="ID"
Me.heading(1)="FirstName"
Me.heading(2)="LastName"
Me.heading(3)="Phone"
Me.heading(4)="Zip"
The following example in the DropObject event handler of a ListBox adds a row for each item being dropped.
Do
If Obj.TextAvailable then
Me.AddRow(Obj.Text)
End if
Loop until Not obj.NextItem
The following example in the MouseEnter event handler of a Canvas changes the mouse pointer to an open hand.
The following code in the MouseDown event handler of an ImageWell creates a DragItem and enables dragging:
d=NewDragItem( Me.left, Me.top, Me.width, Me.height)
d.Picture= Me.image
d.Drag //Allow the drag
See Also
Self keyword.